package com.ailot.cloud.base.security.utils;

import cn.hutool.json.JSONUtil;
import com.ailot.cloud.base.common.dto.Result;
import lombok.SneakyThrows;
import org.springframework.http.MediaType;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ResponseUtil {

    @SneakyThrows
    public static HttpServletResponse response(HttpServletResponse httpServletResponse, Result<String> result){
        httpServletResponse.setContentType(MediaType.APPLICATION_JSON_VALUE);
        httpServletResponse.setCharacterEncoding("UTF-8");
        httpServletResponse.getWriter().write(JSONUtil.toJsonStr(result));
        httpServletResponse.getWriter().flush();
        httpServletResponse.getWriter().close();
        return httpServletResponse;
    }

}
